package com.big.pay.init;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 *  项目初始化

 * */
@Component
public class ProjectInit implements ApplicationRunner {

    //应用id
    @Value("${alipay.appId}")
    private String appId;

    //私钥
    @Value("${alipay.privateKey}")
    private String privateKey;

    //公钥
    @Value("${alipay.publicKey}")
    private String publicKey;

    //支付宝网关
    @Value("${alipay.serverUrl}")
    private String serverUrl;

    //成功返回网址
    @Value("${alipay.returnUrl}")
    private String returnUrl;

    //格式
    @Value("${alipay.format}")
    private String format;

    //字符集
    @Value("${alipay.charset}")
    private String charset;

    //支付宝标志类型
    @Value("${alipay.signType}")
    private String signType;

    //支付成功后的接口回调地址，不是回调的友好页面，不要弄混了

    /**
     *  项目初始化事件
     * */
    @Override
    public void run(ApplicationArguments args) throws Exception {
//        初始化支付宝SDK
       this.DefaultAlipayClientInit();
        System.out.println("**********支付宝SDK初始化完成**********");
    }

    public DefaultAlipayClient DefaultAlipayClientInit(){
        return new DefaultAlipayClient(serverUrl, appId, privateKey, format, charset, publicKey, signType);
    }





}
